home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_dev.lha / GMSDev / Source / C / Keyboard / Keyboard.c next >
Encoding:
C/C++ Source or Header  |  1998-07-05  |  1.9 KB  |  68 lines

  1. /* Dice: dcc -l0 -mD dpk.o tags.o Keyboard.c -o Keyboard
  2. **
  3. ** This routine tests the keyboard module routines.  Once it puts up the Screen,
  4. ** you can type things and the program will read the values and print them out
  5. ** to IceBreaker.  When your are finished, push the LMB to see the results.
  6. **
  7. ** This is an excellent way of learning how to read the keyboard, and you can
  8. ** see how the different Qualifier flags work.
  9. **
  10. ** If you have a PC or Amiga hooked up over a null modem, I would recommend
  11. ** sending IceBreaker output to it so that you can see the results in real-time.
  12. */
  13.  
  14. #include <proto/dpkernel.h>
  15. #include <system/debug.h>
  16. #include <input/keyboard.h>
  17.  
  18. BYTE *ProgName      = "Keyboard Reader";
  19. BYTE *ProgAuthor    = "Paul Manias";
  20. BYTE *ProgDate      = "February 1998";
  21. BYTE *ProgCopyright = "DreamWorld Productions (c) 1996-1998.  Freely distributable.";
  22. BYTE *ProgShort     = "Keyboard demo.";
  23.  
  24. void main(void)
  25. {
  26.   struct Keyboard *key = NULL;
  27.   struct JoyData  *joy = NULL;
  28.   struct GScreen  *screen = NULL;
  29.   WORD i;
  30.  
  31.   if (screen = Init(Get(ID_SCREEN),NULL)) {
  32.      key = Get(ID_KEYBOARD);
  33.      key->Flags = KF_AUTOSHIFT;
  34.  
  35.      if (key = Init(key,NULL)) {
  36.         if (joy = Init(Get(ID_JOYDATA),NULL)) {
  37.  
  38.            DMsg("Proceeding with Keyboard processor.");
  39.  
  40.            Display(screen);
  41.  
  42.            do {
  43.               Query(key);
  44.  
  45.               for (i = 0; i < key->AmtRead; i++) {
  46.                  DPrintF("Keyboard:","Qual: $%X, Key: %c ($%X)", key->Buffer[i].Qualifier, key->Buffer[i].Value, key->Buffer[i].Value & 0x00ff);
  47.               }
  48.  
  49.               for (i = 0; i < 30; i++) {
  50.                  WaitVBL();
  51.               }
  52.  
  53.               Query(joy);
  54.            } while (!(joy->Buttons & JD_LMB));
  55.  
  56.         Free(joy);
  57.         }
  58.         else EMsg("Could not initialise joystick.");
  59.  
  60.      Free(key);
  61.      }
  62.      else EMsg("Could not initialise keyboard.");
  63.   Free(screen);
  64.   }
  65.  
  66. }
  67.  
  68.